package top.oauth2.api.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import top.oauth2.common.util.captcha.ImageCaptchaParams;
import top.oauth2.common.util.captcha.ImageCaptchaUtil;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 测试接口
 * Created by macro on 2020/6/19.
 */
@RestController
public class DemoController {

    @GetMapping("/demo1")
    public String demo1(String state, String code, String scope) {
        System.out.println(state);
        System.out.println(code);
        System.out.println(scope);

        return "Hello demo1.";
    }

    @GetMapping("/demo2")
    public String demo2() {
        return "Hello demo2.";
    }

    @GetMapping("/demo3")
    public String demo3() {
        return "Hello demo3.";
    }

    @GetMapping("/img")
    public void getImgCaptcha(HttpServletResponse response) throws IOException {
        ImageCaptchaParams params = new ImageCaptchaParams();
        ServletOutputStream outputStream = response.getOutputStream();
        String s = ImageCaptchaUtil.create(params, outputStream);
        System.out.println(s);
        outputStream.flush();
        outputStream.close();
    }

}
